Assignemnt #121 and 122nd program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: 122nd Program
///File name: Hund21prog.java
///Date Finished:5/5/2016
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Hund21prog
{
public static void main( String[] args ) throws Exception
{
System.out.println( "" );
PrintWriter fileOut;
String name;
int highScore;
Scanner k = new Scanner(System.in);
System.out.println( "You got a high score!" );
System.out.print( "\nPlease enter your score: " );
highScore = k.nextInt();
System.out.print( "Please enter your name; " );
name = k.next();
System.out.println();
try
{
fileOut = new PrintWriter( "score.txt" );
}
catch(IOException e)
{
System.out.println( "Sorry, I can't open the file for editing." );
fileOut = null;
System.exit(1);
}
fileOut.println( name );
fileOut.print( "High Score: " + highScore );
fileOut.close();
}
}
Picture of the output